//
//  NDProductDetailTopView.swift
//  NyamanDana
//
//  Created by 李永彬 on 2025/10/27.
//

import SwiftUI
import Kingfisher

struct NDProductDetailTopView: View {
    let productInfo: NDProductInfo?
    let isLoading: Bool
    
    var body: some View {
        let logoUrl = URL.buildURL(with: productInfo?.cutad ?? "")
        let appName = productInfo?.fascletterism ?? ""
        ZStack {
            // 背景图片
            Image("product_detail_top_bg") // 替换为你的图片名称
                .resizable()
                .scaledToFit()
            
            // 内容
            Group {
                let loanInterest = (productInfo?.lei?.nextine?.pitister ?? "") + ": " + (productInfo?.lei?.nextine?.noable ?? "")
                let loanTerm = (productInfo?.lei?.addish?.pitister ?? "") + ": " + (productInfo?.lei?.addish?.noable ?? "")
                
                VStack(alignment: .leading,) {
                    HStack(spacing: 5) {
                        KFImage(logoUrl)
                            .resizable()
                            .aspectRatio(contentMode: .fill)
                            .frame(width: 20, height: 20)
                            .cornerRadius(3)
                        Text(appName)
                            .font(.system(size: 16, weight: .bold))
                            .foregroundColor(Color(hex: "#271F24"))
                    }
                    Spacer()
                    Text(productInfo?.nupticoupleant ?? "")
                        .font(.system(size: 58, weight: .bold))
                        .foregroundColor(Color(hex: "#FFFFFF"))
                        .minimumScaleFactor(0.3)
                        .lineLimit(1)
                    Spacer()
                    Text(loanInterest)
                        .font(.system(size: 14, weight: .medium))
                        .foregroundColor(Color(hex: "#FFFFFF"))
                    Spacer()
                    Text(loanTerm)
                        .font(.system(size: 14, weight: .medium))
                        .foregroundColor(Color(hex: "#FFFFFF"))
                        .padding(.bottom, 20)
                }
                .frame(maxWidth: .infinity, alignment: .leading)
                .background(Color.clear)
                .shadow(radius: 2)
            }
            .padding(.init(top: 35, leading: 35, bottom: 30, trailing: 20))
        }
    }
}

